﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ActionSystem.Core.Utils
{
    public class ListDictionary<K,V>
    {
        List<K> ks=new List<K>();
        Dictionary<K, V> keyValues = new Dictionary<K, V>();
        public void Add(K key,V value)
        {
            keyValues.Add(key, value);
            ks.Add(key);
        }
        public int Count => keyValues.Count;
        public void Remove(K key)
        {
            keyValues.Remove(key);
            ks.Remove(key);
        }
        public void RemoveAtIndex(int index)
        {
            var k = ks[index];
            keyValues.Remove(k);
            ks.RemoveAt(index);
        }
        public void Clear()
        {
            keyValues.Clear();
            ks.Clear();
        }
        public V GetValue(K key)
        {
            return keyValues[key];
        }
        public V GetValueAtIndexOf(int index)
        {
            return keyValues[ks[index]];
        }
        public K GetKeyAtIndexOf(int index)
        {
            return ks[index];
        }
        public bool ContainsKey(K key)
        {
            return keyValues.ContainsKey(key);
        }
        public bool ContainsValue(V value)
        {
            return keyValues.ContainsValue(value);
        }
        public IEnumerable<V> GetListValues()
        {
            foreach(var k in ks)
            {
                yield return keyValues[k];
            }
        }
        public IEnumerable<K> GetListKeys()
        {
            foreach (var k in ks)
            {
                yield return k;
            }
        }
    }
}
